import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import './provide/cart_provide.dart';
import './pages/shopping_car/cart_item.dart';
import './pages/shopping_car/cart_fotter.dart';


class CartPage extends StatelessWidget {
  const CartPage({Key key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('购物车'),
      ),
      body: FutureBuilder(
        future: _getCartInfo(context),
        builder: (context,snapshot){
          if(snapshot.hasData){
            List cartList = Provide.value<CartProvide>(context).cartList;
            return Stack(
              children: <Widget>[
                Provide<CartProvide>(
                  builder: (context,child,childCatgoty){
                    cartList = Provide.value<CartProvide>(context).cartList;
                    return ListView.builder(
                      itemCount:cartList.length,
                      itemBuilder: (context,index){
                      return CartItem(
                        cartList[index]
                        );
                      },
                    );
                  },
                ),
                Positioned(
                  // width: ScreenUtil().setWidth(745.0),
                  bottom: 0.0,
                  left: 0.0,
                  child: CatFotter(),
                )
              ],
            );
          }else{
            return Text('正在加载');
          }
        },
      ),
    );
  }
  Future<String> _getCartInfo(BuildContext context) async{
      var data = await Provide.value<CartProvide>(context).getCartInfo();
      return 'end';
    } 
}